<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <link rel="stylesheet" href="./css/swiper.min.css">
    <link rel="stylesheet" href="./css/animate_ios.css" />
    <link rel="stylesheet" href="./css/dm2.css" />
    <link rel="stylesheet" href="./css/dm.css" />
    <style>
        /* 清空样式 */
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            height: 100%;
        }

        .swiper-container {
            width: 100%;
            height: 100%;
        }

        .swiper-slide {
            width: 100%;
            background-size: 100% 100%;
            /* background-size: cover; */
            /* background-size: contain; */
            background-repeat: no-repeat;
            background-position: center;

        }

        p {
            line-height: 32px;
        }

        /*
        span {
            font-size: 15px;
            color: rgb(255, 255, 255);
            margin: 0px 5px;
        } */

        #music1,
        #audio_btn {
            width: 39px;
            height: 39px;
            position: fixed;
            top: 3%;
            right: 3%;
            z-index: 100;
        }

        #audio_btn img {
            width: 100%;
            height: 100%;
        }

        #dm_button {
            position: fixed;
            top: 10%;
            right: 2.5%;
            z-index: 100;
            height: 44px;
            width: 44px;
        }

        #dm_button img {
            height: 100%;
            width: 100%;
        }

        #dm_send {
            margin-left: 50px;
            width: 100%;
            position: fixed;
            bottom: 27px;
            left: 0;
            z-index: 990;
        }

        #show {
            position: fixed;
            top: 17.7%;
            right: 3.3%;
            z-index: 100;
            height: 38px;
            width: 38px;
        }

        #show img {
            height: 100%;
            width: 100%;
        }
    </style>

    <style type="text/css">
        .name_last p {
            margin-top: 5%;
            margin-bottom: 5%;
            font-size: 20px;
            letter-spacing: 8px;
            color: #FFFFFF;
            font-family: SimHei;
            font-weight: bolder;
        }

        .xw p {
            width: 100%;
            letter-spacing: 3px;
            /* text-align: center; */
            color: #FFFFFF;
            font-family: SimHei;
            font-weight: bolder;

        }


        .content p {
            height: 100%;
            /*margin-top: -20px;*/
            font-size: 4vh;
            letter-spacing: 5px;
            color: #FFFFFF;
            font-family: STXinwei;
            /* text-decoration: underline; */
            line-height: 8vh;
        }


        .bz img {
            width: 100%;
            height: 100%;
        }
    </style>
    <title>我想对党说</title>
</head>

<body>

<!-- 音乐 -->
<div id="music1">
    <audio id="music" autoplay="autoplay" loop="loop">
    </audio>
    <a id="audio_btn">
        <img src="./img/music.png" id="music_btn2" border="0">
    </a>
</div>


<!-- 弹幕留言 -->

<a id="dm_button"><img src="./img/dm_kai.png" /></a>
<span id="dm_send">
        <input type="text" style="height: 25px;" class="form-control" name="content" id="barrage_content" placeholder="添加弹幕内容">
        <button style="height: 40px;" class="btn btn-primary" id="submit_barraget" onclick="submitLy()">发送</button>
    </span>

<!-- <iframe id="id_iframe" name="nm_iframe" style="display:none;"></iframe> -->

<div class="swiper-container">
    <!-- <div class="content">
        <div class="content-barrage" id="content-barrage">

        </div>
    </div> -->
    <div id="dm-main">
        <div id="dm-screen" style="height:150px; margin-top: 40px"></div>
    </div>
    <div class="swiper-wrapper">
        <!-- slide1 欢迎页-->
        <div class="swiper-slide" style="background-image: url(./img/dang_1.jpg);" id="s1">

        </div>
        <!-- slide2 卷首语-->
        <div class="swiper-slide" style="background-image: url(./img/dang_2.jpg);" id="s2">
            <div style="color:#fff;margin:auto;margin-top:32%;font-size:16px;text-align: center;">
                <p>
                    今年是中国共产党成立100周年。<br />

                </p>
                <br />
                <p>
                    百年征程波澜壮阔；<br />
                    百年初心历久弥坚。<br />
                    从播下革命火种的小小红船；<br />
                    到领航复兴伟业的巍巍巨轮，<br />
                    在百年奋斗历程中，<br />
                    我们党领导人民取得了，<br />
                    举世瞩目的辉煌成就！<br />
                </p>
            </div>
        </div>

        <div class="swiper-slide" style="background-image: url(./img/dang_3.jpg);" id="s3">
            <div style="color:#fff;margin-left:10%;margin-top:32%;font-size:16px;">
                <p id="quote">
                    从<span>1921</span>年到<span>2021</span>年<br />
                    中国共产党走过了整整一百年的历程，<br />
                    这是用鲜血、汗水、泪水、<br />
                    勇气、智慧、力量写就的百年<br />
                </p>
            </div>
        </div>

        <div class="swiper-slide" style="background-image: url(./img/dang_4.jpg);" id="s4">
            <div style="color:#fff;margin-left:10%;margin-top:32%;font-size:16px;">
                <p>
                    曾记否，<br />
                    <span>1921</span>年<span>7</span>月<span>23</span>日的那一天，<br />
                    中国共产党的正式建立<br />
                    必须坚持走中国特色社会主义道路<br />
                    方向决定前途，<br />
                    道路决定命运，<br />
                    必须坚持以人民为中心，<br />
                    必须坚持深化改革开放。<br />
                </p>
            </div>
        </div>
    </div>

    <!-- js文件引入 -->
    <script src="./js/swiper.min.js"></script>
    <script src="./js/jquery-1.12.4.min.js"></script>
    <script src="./js/TweenMax.min.js"></script>
    <script src="./js/SplitText.min.js"></script>
    <script src="./js/damoo.js"></script>
    <!-- <script src="./js/index.js"></script> -->
    <!-- <script src="./js/new.js"></script> -->
    <!-- swiper初始化 -->
    <script>
        var mySwiper = new Swiper('.swiper-container', {
            direction: 'vertical', // 垂直切换选项
            loop: true, // 循环模式选项
            // loopAdditionalSlides : 20,

            // 分页进度回调函数
            watchSlidesProgress: true,
            watchSlidesVisibility: true,

            on: {
                slideChangeTransitionStart: function () {
                    var id = $(".swiper-slide-active").attr("id");

                    if (id == "s13") {
                        //文字效果1 #13
                        var $quote = $("#s13 > div p"),
                                mySplitText = new SplitText($quote, {
                                    type: "chars"
                                }),
                                splitTextTimeline = new TimelineLite();

                        TweenLite.set($quote, {
                            perspective: 400
                        });

                        function kill() {
                            splitTextTimeline.clear().time(0);
                            mySplitText.revert();
                        }

                        kill();
                        mySplitText.split({
                            type: "chars"
                        })
                        $(mySplitText.chars).each(function (index, el) {
                            splitTextTimeline.from($(el), 0.8, {
                                opacity: 0,
                                force3D: true
                            }, index * 0.03);
                            splitTextTimeline.from($(el), 0.8, {
                                scale: index % 2 == 0 ? 0 : 2,
                                ease: Back.easeOut
                            }, index * 0.03);
                        });
                    };


                    if (id == "s2") {
                        //文字效果2 slideDown
                        $("#s2 > div p").hide();
                        $("#s2 > div p").slideDown(1200);
                    };

                    if (id == "s4") {
                        //文字效果3 rollin
                        $("#s4 > div p").addClass("animated rollIn");
                    };

                    if (id == "s3") {
                        // 文字效果4 rubberBand
                        $("#s3 > div p").addClass("animated rubberBand");
                    };

                    if (id == "s5") {
                        // 文字效果5 swing
                        $("#s5 > div p").addClass("animated swing");
                    };

                    if (id == "s6") {
                        // 文字效果6 wobble
                        $("#s6 > div p").addClass("animated wobble");
                    };

                    if (id == "s7") {
                        // 文字效果7 heartBeat
                        $("#s7 > div p").addClass("animated swing");
                    };

                    if (id == "s8") {
                        // 文字效果8 fadeInLeft
                        $("#s8 > div p").addClass("animated fadeInLeft");
                    };

                    if (id == "s9") {
                        // 文字效果9 flip
                        $("#s9 > div p").addClass("animated rotateIn");
                    };

                    if (id == "s10") {
                        // 文字效果10 lightSpeedIn
                        $("#s10 > div p").addClass("animated lightSpeedIn");
                    };

                    if (id == "s14") {
                        // 文字效果11 rotateIn
                        $("#s14 > div p").addClass("animated rotateIn");
                    };

                    if (id == "s15") {
                        // 文字效果11 zoomIn
                        $("#s15 > div p").addClass("animated zoomIn");
                    };

                    //离开最后一页显示按钮
                    if (id == "s16" || id == "s1") {
                        $("#audio_btn").show();
                        $("#dm_button").show();
                        $("#show").show();
                    }
                    //文字效果刷新
                    $(".swiper-slide-next > div p").removeClass();
                    $(".swiper-slide-prev > div p").removeClass();


                },
            },
        })
    </script>

    <!--音乐-->
    <script>
        //自动播放
        function audioAutoPlay(id) {
            var audio = document.getElementById(id),
                    play = function () {

                        audio.play();
                        document.removeEventListener("touchstart", play, false);
                    };
            audio.play();
            document.addEventListener("WeixinJSBridgeReady", function () {
                play();
            }, false);
            document.addEventListener('YixinJSBridgeReady', function () {
                play();
            }, false);
            document.addEventListener("touchstart", play, false);
        };
        audioAutoPlay('music');

        $(function () {
            //音乐源
            // var musci_type = $("#musci_type").attr("value");
            // var musci_numb = $("#musci_numb").attr("value");
            // var str = "./music/"+musci_type+"_"+musci_numb+".mp3"


            var str = "./music/b_6.mp3";
            var music = document.getElementById("music");
            music.src = str;
            music.play();

            // 播放/暂停
            var musicBtn = document.getElementById("audio_btn");
            var i = 2;
            var musitimer2;

            function musicfun() {
                i += 2;
                musicBtn.style.transform = "rotate(" + i + "deg)";
            }

            var musitimer = setInterval(musicfun, 60)

            musicBtn.addEventListener("click", function () {
                if (music.paused) {
                    music.play();
                    musitimer2 = setInterval(musicfun, 60);
                } else {
                    music.pause();
                    clearInterval(musitimer);
                    clearInterval(musitimer2);
                    musicBtn.style.transform = "rotate(0deg)";
                }
            })
        })
    </script>


    <!-- 数据 -->
    <script>
        function randomColor(){//十六进制颜色随机
            var r = Math.floor(Math.random()*256);
            var g = Math.floor(Math.random()*256);
            var b = Math.floor(Math.random()*256);
            var color = '#'+r.toString(16)+g.toString(16)+b.toString(16);
            return color;
        }

        //轨道数
        var rows = 6;
        var data = [];
        window.onload = function () {
            var settings = {
                "url": "http://121.196.163.6:8080/comment/pass",
                "method": "GET",
                "timeout": 0,
                "headers": {
                    "Content-Type": "application/json"
                },
            };

            $.ajax(settings).done(function (response) {
                data = JSON.parse(response);
                // 调用方法格式化
                formatDataList(data, rows)
                //发送弹幕
                for (let i = 0; i < data.length; i++) {
                    send(i)
                }
                function send(i) {
                    return setTimeout(function () {
                        let tempColor = randomColor()
                        damoo.emit({ text: formatData[i].text, color: tempColor, index: i }, rows);
                    }, formatData[i].delayTime * 1000)
                }
            });
        }

    </script>

    <!--弹幕-->
    <script type="text/javascript">
        //弹幕开关
        var dm_state = true;
        $("#dm_button").click(function () {
            if (dm_state == false) {
                $("#dm_button img").attr("src", "./img/dm_kai.png");
                $("#dm_send").removeAttr("style");
                damoo.show();
                // startNewDm()
                dm_state = true;
            } else {
                $("#dm_button img").attr("src", "./img/dm_guan.png");
                $("#dm_send").attr("style", "visibility: hidden;");
                damoo.hide();
                // stopNewDm()
                dm_state = false;
            }
        })
    </script>

    <!-- 留言提交-->
    <script>
        //获取当前url中的学号和姓名
        function getXhAndName(strName) {
            var strHref = document.location.toString();
            var intPos = strHref.indexOf("?");
            var strRight = strHref.substr(intPos + 1); //==========获取到右边的参数部分
            var arrTmp = strRight.split("&"); //=============以&分割成数组

            for (var i = 0; i < arrTmp.length; i++) //===========循环数组
            {
                var dIntPos = arrTmp[i].indexOf("=");
                var paraName = arrTmp[i].substr(0, dIntPos);
                var paraData = arrTmp[i].substr(dIntPos + 1);
                if (paraName.toUpperCase() == strName.toUpperCase()) {
                    return paraData;
                }
            }
            return "";
        }
        function submitLy() {
            //判断是否统一认证
            var userName = decodeURI(getXhAndName("name"));
            var userCode = decodeURI(getXhAndName("code"));
            console.log(decodeURI(userName))

            // if (userName != '' && userCode != '') {
                let content = $("#barrage_content").val()
                //发送弹幕，只有自己可看，弹幕放到第一行
                damoo.emit({ text: content, color: '#fff', index: -1 }, 6);
                //将弹幕数据保存到后端数据库
                var settings = {
                    "url": "http://121.196.163.6:8080/comment/insert",
                    "method": "POST",
                    "timeout": 0,
                    "headers": {
                        "Content-Type": "application/json"
                    },
                    "data": JSON.stringify({ "userName": userName, "content": content, "userCode": userCode }),
                };

                $.ajax(settings).done(function (response) {
                });
                $("#barrage_content").val("");
            // }else{
            //     console.log("error")
            // }
        }
    </script>

    <!-- 弹幕new -->
    <script>
        var damoo = new Damoo(document.getElementById('dm-screen'), 'dm-canvas', rows);

        damoo.play();

        var formatData = []  // 格式化后的数据
        //格式化数据
        function formatDataList(data, n) {
            let tempData;
            let tempTime; // 临时延迟时间
            // data代表数据，n代表一共几条道
            for (let i = 0; i < data.length; i++) {
                if (i < n) { // 前n条的延迟时间为i
                    tempData = { "text": data[i].userName + ':' + data[i].content, "delayTime": i, "index": i }
                    formatData.push(tempData)
                } else { // 后面的弹幕根据 i-n条来确定延迟时间
                    let speed = Math.pow(data[i - n].content.length, 1 / 3) * 0.6
                    tempTime = data[i - n].content.length / speed / 2 + formatData[i - n].delayTime // 计算当前延迟时间
                    tempData = { "text": data[i].content, "delayTime": tempTime, "index": i }
                    formatData.push(tempData)
                }
            }
        }

    </script>
</body>

</html>